<?php
require('../conexiones/config.php');
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die('No es posible realizar la conexion con el servidor.' . mysql_error());
        mysql_select_db(SQL_DB,$conn);
require('../conexiones/config.inc.php');
require('url_factory.inc.php');

$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends

$qstring = "SELECT f.franquicia AS value, f.id, b.categoria_id, e.categoria
            FROM franquicias f, categorias_link b, categorias e
			WHERE franquicia LIKE '%".$term."%'
			AND f.id = b.franquicia_id
			AND b.categoria_id = e.id
			AND f.estado = '1'";
$result = mysql_query($qstring);//query the database for entries containing the term

while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values
{
	$row['value'] = utf8_encode(stripslashes($row['value']));
	$url = crear_url_franquicia($row['categoria'], (int)$row['categoria_id'], $row['value'], (int)$row['id']);
	$row_set[] = array('value' => $row['value'], 'url' => $url);//build an array
}
echo json_encode($row_set);//format the array into json data
?>